// Package main provides a static develop web server with semantic-ui
package main

import (
	"bytes"
	"flag"
	"log"
	"os"

	"github.com/go-martini/martini"
	"github.com/martini-contrib/gzip"
	"github.com/martini-contrib/staticbin"
)

var (
	addr    = flag.String("addr", "127.0.0.1:3000", "listen on ip:host")
	dir     = flag.String("dir", "./", "static website root directory")
	logfile = flag.String("logfile", "./web.log", "output logfile")
	buf     bytes.Buffer
)

func main() {
	t := log.New(&buf, "logger: ", log.Lshortfile)
	f, err := os.OpenFile(*logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		t.Fatalf("error opening file: %v", err)
	}
	defer f.Close()

	flag.Parse()
	m := martini.Classic()
	m.Map(log.New(f, "[martini]", log.LstdFlags))
	m.Use(gzip.All())
	m.Use(martini.Static(*dir))
	m.Use(staticbin.Static("static", Asset, staticbin.Options{true, "dir"}))
	m.RunOnAddr(*addr)
}
